package com.front.managementfront.driver.service.serviceimpl;

import com.baomidou.mybatisplus.core.metadata.IPage;
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.front.managementfront.driver.entity.HktsDriverDetail;
import com.front.managementfront.driver.mapper.HktsDriverDetailMapper;
import com.front.managementfront.driver.service.IHktsDriverDetailService;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import org.springframework.stereotype.Service;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.transaction.annotation.Transactional;
import org.apache.commons.lang.StringUtils;
import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import com.baomidou.mybatisplus.core.toolkit.Wrappers;

import java.util.List;

/**
 * <p>
 * 服务实现类
 * </p>
 *
 * @author yck
 * @since 2021-08-06
 */
@Service
@Transactional
public class HktsDriverDetailServiceImpl extends ServiceImpl<HktsDriverDetailMapper, HktsDriverDetail> implements IHktsDriverDetailService {


    @Autowired
    private HktsDriverDetailMapper hktsDriverDetailMapper;

    @Override
    public IPage<HktsDriverDetail> selectPage(Page<HktsDriverDetail> page, HktsDriverDetail hktsDriverDetail) {
        QueryWrapper<HktsDriverDetail> query = Wrappers.query();
        QueryWrapper<HktsDriverDetail> entityWrapper = getEntityWrapper(query, hktsDriverDetail);
        return hktsDriverDetailMapper.selectPage(page, entityWrapper);
    }


    @Override
    public List<HktsDriverDetail> selectList(HktsDriverDetail hktsDriverDetail) {
        QueryWrapper<HktsDriverDetail> query = Wrappers.query();
        QueryWrapper<HktsDriverDetail> entityWrapper = getEntityWrapper(query, hktsDriverDetail);
        return hktsDriverDetailMapper.selectList(entityWrapper);
    }

    /**
     * 公共查询条件
     *
     * @param entityWrapper
     * @return
     */
    public QueryWrapper<HktsDriverDetail> getEntityWrapper(QueryWrapper<HktsDriverDetail> entityWrapper, HktsDriverDetail hktsDriverDetail) {
        //条件拼接
        if (StringUtils.isNotBlank(hktsDriverDetail.getDriverId())) {
            entityWrapper.like("driver_id", hktsDriverDetail.getDriverId());
        }
        return entityWrapper;
    }
}
